<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Story
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
?>
<!-- FOLLOW -->
<style type="text/css">
.stories_follow .story_radio_loading
{
     background-image: url(application/modules/Core/externals/images/loading.gif);
     background-repeat: no-repeat;
     overflow: hidden;
}
.stories_follow .story_radio_loading a
{
     visibility: hidden;
}
.stories_follow .buttonlink{
	font-size: .8em;
}
</style>
<!-- FOLLOW -->

<?php $story = $this->story; ?>
<div class='story_profile_tools'>

	<!-- FOLLOW -->
	<?php if ($this->viewer_id): ?>
	<script type="text/javascript">
	    en4.core.runonce.add(function(){
	         $$('#follow_options<?php echo $story->story_id; ?> a').addEvent('click', function(){
	              var option_id = this.get('data');
	              $$('#follow_options<?php echo $story->story_id; ?> .story_profile_tools').each(function(row){
	                row.className= 'story_radio_loading';
	                });
	              new Request.JSON({
	                  url: '<?php echo $this->url(array('module' => 'story', 'controller' => 'widget', 'action' => 'story-follow'), 'default', true); ?>',
	                  method: 'post',
	                  data : {
	                    format: 'json',
	                      'story_id': <?php echo $story->story_id; ?>,
	                      'option_id' : option_id
	                  },
	                  onComplete: function(responseJSON, responseText) {
	                      if (responseJSON.error) {
	                        alert(responseJSON.error);
	                       }else{
	                        $$('#follow_options<?php echo $story->story_id; ?> .story_radio_loading').each(function(row){
	                            row.className= 'story_profile_tools';
	                            });
	                         var text_follow = '<?php echo $this->translate('Follow'); ?>'; 
	                         var data_follow = 1;
	                         if(option_id==1){
	                          text_follow = '<?php echo $this->translate('Unfollow'); ?>'; 
	                          data_follow = 0;
	                         } 
	                         $$('#follow_options<?php echo $story->story_id; ?> .story_profile_tools a').each(function(row){
	                            row.setAttribute("data", data_follow);
	                           });
	                          $$('#follow_options<?php echo $story->story_id; ?> .story_profile_tools a').each(function(row){
	                            row.innerHTML = text_follow;
	                           });
	                       }
	                   }
	              }).send();
	         });
	    });
	</script>
	<?php $follow = $story->getFollow(array('story_id'=>$story->story_id,'user_id'=>$this->viewer_id)); ?>
	  <div style="float:left;margin-right:10px;" class="stories_follow" id="follow_options<?php echo $story->story_id; ?>">
	    <?php if ($follow == 1): ?>
	    <div class="story_profile_tools">
	        <a href="javascript:;" data="0" class="buttonlink icon_story_viewall "><?php echo $this->translate('Unfollow'); ?></a>
	    </div>
	    <?php endif; ?>
	    <?php if ($follow == 0): ?>
	    <div class="story_profile_tools">
	        <a href="javascript:;" data="1" class="buttonlink icon_story_viewall "><?php echo $this->translate('Follow'); ?></a>
	    </div>
	    <?php endif; ?>
	  </div>
	<?php endif; ?>
	<!-- FOLLOW -->

  <?php echo $this->htmlLink(Array('module'=> 'activity', 'controller' => 'index', 'action' => 'share', 'route' => 'default', 'type' => 'story', 'id' => $this->story->getIdentity(), 'format' => 'smoothbox'), $this->translate("Share"), array('class' => 'buttonlink icon_story_share smoothbox')); ?>
  <?php echo $this->htmlLink(Array('module'=> 'core', 'controller' => 'report', 'action' => 'create', 'route' => 'default', 'subject' =>  $this->story->getGuid(), 'format' => 'smoothbox'), $this->translate("Report"), array('class' => 'buttonlink icon_story_report smoothbox')); ?>
</div>
